#============================================================
#	Ground Enemy Base
#============================================================
# @datetime: 2022-5-12 01:51:38
#============================================================
class_name GroundEnemyBase
extends EnemyState


var move_controller : SimplePlatformController
var fall_wrapper : CollisionWrapper


#============================================================
#   Set/Get
#============================================================
#(override)
func get_blackboard() -> GroundEnemyStateBlackboard:
	return .get_blackboard() as GroundEnemyStateBlackboard

func is_can_fall() -> bool:
	return fall_wrapper.is_enabled()

func is_can_jump() -> bool:
	return get_host().is_on_floor() and move_controller.jump_enabled

func has_player() -> bool:
	return get_blackboard().get_collision().detect_player.has_bodys()

func get_player() -> Player:
	return get_blackboard().get_collision().detect_player.get_bodys()[0] as Player

func get_move_controller() -> SimplePlatformController:
	return move_controller

##  没有路了 
func is_no_way() -> bool:
	return not get_blackboard().get_type_layer().collision._no_way.is_colliding()

##  前面有墙 
func has_wall() -> bool:
	return get_host().is_on_wall()


#============================================================
#   内置
#============================================================
func _ready():
	yield(owner, "ready")
	move_controller = get_blackboard().get_layer().controller.move_controller
	fall_wrapper = WrapperInterface.get_wrapper(get_host(), CollisionWrapper)


#============================================================
#   操控
#============================================================
##  切换方向
## @dir  如果不传入参数，则自动切换到另一个方向
func change_direction(dir: float = INF) -> void:
	if dir == INF:
		move_controller.update_direction(move_controller.get_direction() * -1)
	else:
		move_controller.update_direction(Vector2(dir, 0))

##  按方向移动
## @direction  
## @return  
func input_move_direction(direction: float) -> bool:
	move_controller.move_direction(Vector2(direction, 0))
	return true

##  向前移动 
## @return  
func input_forward_move() -> bool:
	move_controller.move_direction(move_controller.get_direction())
#	Logger.info(self, [move_controller.get_direction()])
	return true

##  跳跃
## @height  
func input_jump(height: float = INF, force: bool = false):
	if is_can_jump():
		move_controller.jump(height, force)
		return true
	return false

##  下落 
## @return  
func input_fall() -> bool:
	if is_can_fall():
		fall_wrapper.disabled()
		return true
	return false

